/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:ces.org.course.ext.xml</p>
 * <p>File:DictionaryDocument.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 May 20, 2019 12:36:35 PM
 */
package ces.org.course.ext.xml;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date May 20, 2019 12:36:35 PM
 * @version 1.0.2019
 */
public class DictionaryDocument {

	public static Dictionary toBean(final String file) {
		try (InputStream stream = DictionaryDocument.class.getClassLoader().getResourceAsStream(file)) {
			return (Dictionary) unmarshaller().unmarshal(stream);
		} catch (JAXBException | IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static Dictionary toBean(final File file) {
		try {
			return (Dictionary) unmarshaller().unmarshal(file);
		} catch (JAXBException e) {
			throw new RuntimeException(e);
		}
	}
	
	private static Unmarshaller unmarshaller() throws JAXBException {
		JAXBContext context = JAXBContext.newInstance(Dictionary.class);
		return context.createUnmarshaller();
	}
}
